package com.kk.controller;

import com.kk.annotation.OperationLog;
import com.kk.common.Result;
import com.kk.enums.OperationType;
import com.kk.pojo.entity.SysUser;
import com.kk.pojo.request.LoginRequest;
import com.kk.pojo.request.UserPageRequest;
import com.kk.pojo.request.UserRegisterRequest;
import com.kk.pojo.vo.LoginUserVO;
import com.kk.service.SysMenuService;
import com.kk.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author kl
 * @version 1.0
 * @description: TODO
 * @date 2025/10/14 上午10:07
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class SysUserController {

    private final SysUserService sysUserService;

    private final SysMenuService sysMenuService;


    @PostMapping("/login")
    public Result<LoginUserVO> loginController(
            @RequestBody LoginRequest request ){
       LoginUserVO vo =  sysUserService.loginService(request);
        return Result.success(vo);
    }

    @GetMapping("/getMenus")
    @OperationLog(
            module = "用户管理",
            type = OperationType.QUERY,
            description = "查询用户菜单"
    )
    @PreAuthorize("hasAuthority('system:menu:list')")
    public Result getMenusController(){
        return Result.success(sysMenuService.getMenusByUserIdService());
    }


    @PostMapping("/register")
    public Result<Boolean> registerController(
            @RequestBody UserRegisterRequest request
    ){
        return Result.success(sysUserService.registerService(request));
    }

    @GetMapping("/getUserPage")
    @OperationLog(
            module = "用户管理",
            type = OperationType.QUERY,
            description = "查询用户列表"
    )
    @PreAuthorize("hasAuthority('system:user:list')")
    public Result getUserPageController(UserPageRequest pageRequest){
        return Result.success(sysUserService.getUserPage(pageRequest));
    }

}
